<template>
	<view class="" style="padding-top: 30rpx;">
		<view class="chwl" v-for="(item,index) in list" :key="index" @click="godetail(item)">
			<u-image border-radius="6" width="164rpx" height="137rpx" :src="item.logo"></u-image>
			<view class="chwl-right">
				<uni-title title="">{{item.title}}</uni-title>
				<view class="chwl-right1" >
					<button class="mini-btn" v-if="item.order.status===0" style="height: 54rpx;line-height: 54rpx;border-radius: 50rpx;" type="default" size="mini">上传凭证</button>
					<button class="mini-btn" v-else :disabled="true" style="height: 54rpx;line-height: 54rpx;border-radius: 50rpx;color: rgba(0,0,0,.3);background-color: #f7f7f7;" type="default" size="mini">{{item.order.status===1?'待结算':'已结算'}}</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		data() {
			return {
				list:[]
			};
		},
		onShow() {
			this.getList()
		},
		methods:{
			getList(){
				const that = this
				this.$u
					.post('/wxapi/Api/shopInfo', {
						token: this.vuex_token.accessToken
					})
					.then(res => {
						uni.getLocation({
							type: 'gcj02',
							altitude: true,
							success(lacation) {
								that.list = []
								res.data.map((row,index)=>{
									if(row.latitude){
										row.distance = that.distance(lacation.latitude,lacation.longitude,row.latitude,row.longitude)
									}
									that.list.push(row)
								})
								var len = that.list.length;
								for (var i = 0; i < len-1; i++) {
								    for (var j = 0; j < len - 1 - i; j++) {
								         // 相邻元素两两对比，元素交换，大的元素交换到后面
								        if (that.list[j].distance > that.list[j + 1].distance) {
								            var temp = that.list[j];
								            that.list[j] = that.list[j+1];
								            that.list[j+1] = temp;
								        }
								    }
								}
							}
						})
					});
			},
			//获取路径距离
			distance(lat1,lng1,lat2,lng2){
			    if(lat1 && lng1 && lat2 && lng2){
			      let radLat1 = this.rad(lat1);
			      let radLat2 = this.rad(lat2);
			      let a = radLat1 - radLat2;
			      let b = this.rad(lng1) - this.rad(lng2);
			      let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
			      s = s * 6378.137;
			      // EARTH_RADIUS;
			      s = Math.round(s * 10000) / 10000;
			      return s
			    }else{
			      return 0
			    }
			},
			rad(d){
			    return d*Math.PI/180.0
			},
			godetail(row){
				uni.setStorageSync('detailInfo',row)
				uni.navigateTo({
					url:'../../../up/up'
				})
			}
		}
	}
</script>

<style scoped>
	.chwl{
		width: 714rpx;
		height: 198rpx;
		margin-left: 20rpx;
		box-sizing: border-box;
		padding: 24rpx 15rpx 38rpx 18rpx;
		display: flex;
		background-color: #fff;
		position: relative;
	}
	.chwl-right{
		flex: 1;
		margin-left: 18rpx;
	}
	.chwl-right1{
		color:#c8c8c8 ;
	}
	.chwl-right1 button{
		width: 180rpx;
		height: 44rpx;
		background-color: #fb4d4e;
		position: absolute;
		right: 15rpx;
		bottom: 30rpx;
		color: #fff;
		line-height: 44rpx;
		border-radius: 20rpx;
	}
	.chwl-right1 button::after{
		border:0;
	}
</style>
